package org.zpmis.domain.project.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.zpmis.common.utils.SpringUtil;
import org.zpmis.domain.project.model.ProjectTask;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Data
public class SubTaskQueryVo implements Serializable {
    /**
     * 任务id
     */
    private Long id;

    /**
     * 任务名称
     */
    private String name;

    /**
     * 任务类型
     */
    private Integer type;

    /**
     * 关联项目id
     */
    private Long projectId;

    /**
     * 关联项目名称
     */
    private String projectName;

    /**
     * 任务级别
     */
    private Integer level;

    /**
     * 上级任务
     */
    private Long parentId;

    /**
     * 任务描述
     */
    private String description;

    /**
     * 任务描述附件
     */
    private String descAttachment;

    /**
     * 任务计划开始时间
     */
    private String planStartTime;

    /**
     * 任务计划结束时间
     */
    private String planEndTime;

    /**
     * 任务开始时间
     */
    private String startTime;

    /**
     * 任务结束时间
     */
    private String endTime;

    /**
     * 工时
     */
    private BigDecimal workHours;

    /**
     * 指派给人
     */
    private Long sysUid;

    /**
     * 指派给人
     */
    private String sysUserName;

    /**
     * 任务完成结果
     */
    private String completeResult;

    /**
     * 任务结果附件
     */
    private String resultAttachment;

    /**
     * 任务创建人
     */
    private String createPerson;

    /**
     * 状态 0新建 1进行中 2已完成
     */
    private Integer status;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 任务进度
     */
    private String progress;

    /**
     * 子任务集合
     */
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    private List<SubTaskQueryVo> subTaskQueryVoList;

    public SubTaskQueryVo(ProjectTask projectTask) {
        this.id = projectTask.getId();
        this.name = projectTask.getName();
        this.type = projectTask.getType();
        this.projectId = projectTask.getProjectId();
        this.level = projectTask.getLevel();
        this.parentId = projectTask.getParentId();
        this.description = projectTask.getDescription();
        this.descAttachment = projectTask.getDescAttachment();
        this.planStartTime = projectTask.getPlanStartTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getPlanStartTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.planEndTime = projectTask.getPlanEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getPlanEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.startTime = projectTask.getStartTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getStartTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.endTime = projectTask.getEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.workHours = projectTask.getWorkHours();
        this.sysUid = projectTask.getSysUid();
        this.completeResult = projectTask.getCompleteResult();
        this.resultAttachment = projectTask.getResultAttachment();
        this.createPerson = projectTask.getCreatePerson();
        this.status = projectTask.getStatus();
        this.createId = projectTask.getCreateId();
        this.createTime = projectTask.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(projectTask.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.progress = projectTask.getProgress();
    }
}